package cate.game.play.buff.h;

import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import easy.java.struct.ref.DoubleRef;

/**
 * 完全分摊其伤害15%，自身最多扣除15%最大生命值，庇护效果自身生命低于30%或我方人数小于3时无法触发
 */
public class 四羊奇偶援护BH extends BuffHandler {

	private double 分担比例;
	private double 最大系数;
	private int 检测血量;
	private int 检测人数;

	//分担比例=1500&最大系数=1500&检测血量=3000&检测人数=3
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		分担比例 = args.getWDouble("分担比例", 0d);
		最大系数 = args.getWDouble("最大系数", 0d);
		检测血量 = args.getInt("检测血量", 0);
		检测人数 = args.getInt("检测人数", 0);
	}

	@Override
	public void shareDamage(ActionCtx action, Fighter actor, int reason, DoubleRef doubleRef) {
		if (buff.caster.isDead()) {
			return;
		}
		if (buff.caster.getFightTeam().getFightersAlive().size() < 检测人数) {
			return;
		}
		if (buff.caster.attr.total().hpCurRate() <= 检测血量) {
			return;
		}
		double shareDamage = Math.min(doubleRef.v * 分担比例, buff.caster.attr.total().hpTotal() * 最大系数);
		doubleRef.v -= shareDamage;
		buff.caster.attr.buffHurt(action, actor, shareDamage);

	}
}
